//  手术信息
//  OperationMessageTableViewController.m
//  yilutongxing
//
//  Created by  Mac on 2017/5/8.
//  Copyright © 2017年 YZE. All rights reserved.
//
#import "CommonDefine.h"
#import <QMUITips.h>
#import "NSString+PinYin.h"
#import "OperationMessageTableViewController.h"
#import "DzyImgPicker.h"
#import "IQActionSheetPickerView.h"
#import "OperationInfoBean.h"
#import "PhotosView.h"
#import "DataUtils.h"
#import "PYSearchViewController.h"
#import "RPHospitalInfo.h"
#import "SinglelineTextFormViewController.h"
#import "OperateWayTableViewController.h"

#define URL_GetOperationinfo @"/api/opertion/mine"
#define URL_ModifyOperationinfo @"/api/opertion"
#define URL_SearchHospital @"/api/_search/hospitals?query=" //搜索医院接口
#define URL_SuggestionHospital @"/api/commonhospitals?page=0&size=10000" //搜索医院界面中的建议数据接口

@interface OperationMessageTableViewController ()<NetworkUtilsDelegate, PYSearchViewControllerDelegate, PYSearchViewControllerDataSource,
                                                  DzyImgDelegate, IQActionSheetPickerViewDelegate, SinglelineTextFormViewControllerDelegate,
                                                  OperateWayTableViewControllerDelegate>
@property (strong, nonatomic) IBOutlet UITableViewCell *otherdiacell;
@property(nonatomic,strong)DzyImgPicker *DzyView;
@property (nonatomic ) NSMutableDictionary *pickerIndexCache;

@property(nonatomic,strong)NSArray *itemNameArr;
@property(nonatomic,strong)NSMutableArray *controlArr;//UI数组
@property(nonatomic,strong)NSArray *propertyNameArr;//数据模型名称数组,用于方便取值赋值
@property(nonatomic,strong)OperationInfoBean *opinfo;//数据模型
@property(nonatomic,strong)NSMutableDictionary *opinfoDic;//数据字典

@property(nonatomic,strong)NSArray *statusArr;//术前术后状态数组
@property(nonatomic,strong)NSArray *ogonOriginArr;//器官来源数组

@property(nonatomic,strong)NSIndexPath *tempIndexPath;
@property(nonatomic, strong) NSMutableArray *picCacheArr;//UIImageView的缓存
@property(nonatomic, strong) NSMutableDictionary *picCacheDic;//图片下载标识的缓存
@property (nonatomic, strong) NSMutableDictionary *imgPickerDic;//图片选择控件缓存
//医院搜索相关
@property (nonatomic, strong) NSArray *commonHospitalArr;//常用医院
@property (nonatomic, retain) NSArray *hospitalArr;//所有医院
@property (nonatomic, retain) NSMutableArray *tobeChoosenArr;//备选医院
@property (nonatomic, retain) NSMutableArray *sortedHospitalArr;//整理好的医院名称数组
@property (nonatomic, assign) BOOL isSearched;//搜索状态

@property (strong,nonatomic) NSArray *picCache_imgUrl;//imgUrl图片数据缓存,以避免使用相同字段导致数据不一致引起的Bug
@end


@implementation OperationMessageTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title=@"诊疗过程";
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(modifyAction)];
    UIImage *leftImage=[[UIImage imageNamed:@"返回"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *leftButtonItem=[[UIBarButtonItem alloc]initWithImage:leftImage style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem=leftButtonItem;
    
    self.clearsSelectionOnViewWillAppear = YES;
    
    self.itemNameArr = @[@"原发疾病", @"其它疾病", @"病理诊断", @"器官来源", @"手术日期",
                         @"手术医生", @"手术医院", @"手术方式", @"综合图片"];
    self.propertyNameArr = @[@"primDisease", @"otherDiseases", @"diagnosis", @"donor",
                             @"opTime", @"docName", @"hospital_name", @"optype_placeholder", @"imgUrl"];
    self.controlArr = [NSMutableArray array];
    self.picCacheArr = [NSMutableArray array];
    self.picCacheDic = [NSMutableDictionary dictionary];
    self.imgPickerDic = [NSMutableDictionary dictionary];
    
    [[YZENetwork sharedInstace]getRequestWithUrl:[BASE stringByAppendingString:URL_GetOperationinfo]
                                      parameters:nil
                                        delegate:self
                                      requestTag:1
                                    successBlock:^(id responseObject)
    {
        //self.opinfo = [OperationInfoBean mj_objectWithKeyValuesAdd:responseObject];
        self.opinfoDic = [responseObject mutableCopy];
        [self convertData2Desc:self.opinfoDic];
        self.opinfo = [OperationInfoBean mj_objectWithKeyValuesAdd:self.opinfoDic];
        [self.tableView reloadData];
    }];
    
    dispatch_async(GLOBAL_BG_QUEUE, ^{
        [self getHostpitalData];
    });
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 业务逻辑
-(void)back{
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)modifyAction{
    NSMutableDictionary *tmpDic = self.opinfo.mj_keyValuesAdd;
    [self convertDesc2Data:tmpDic];
    self.opinfo = [OperationInfoBean mj_objectWithKeyValuesAdd:tmpDic];
    //将缓存的图片数据传递给opinfo
    tmpDic = self.opinfo.mj_keyValuesAdd;
    tmpDic[@"imgUrl"] = _picCache_imgUrl[0];
    
    tmpDic[@"operationOperandiDTO"][@"identical_type"] = nil;
    
    //上传数据
    [[YZENetwork sharedInstace]putRequestWithUrl:[BASE stringByAppendingString:URL_ModifyOperationinfo] parameters:tmpDic delegate:self requestTag:2 successBlock:^(id responseObject) {
        [QMUITips hideAllToastInView:self.view animated:YES];
        [QMUITips showSucceed:@"已保存手术信息!" inView:self.view hideAfterDelay:1];
    }];
    [QMUITips showLoadingInView:self.view];
}

/**
 将某些数据的内部数据格式转换为用户友好表达
 */
-(void)convertData2Desc:(NSMutableDictionary*)dataDic{
    if ([dataDic objectForKey:@"stage"]) {
        NSString *val = [dataDic objectForKey:@"stage"];
        if ([val isEqualToString:@"BEFORE"]) {
            val = @"手术前";
        }
        else {
            val = @"手术后";
        }
        [dataDic setObject:val forKey:@"stage"];
    }
    if ([dataDic objectForKey:@"donor"]) {
        NSString *val = [dataDic objectForKey:@"donor"];
        if ([val isEqualToString:@"RELATED"]) {
            val = @"活体";
        }
        else if ([val isEqualToString:@"UNRELATED"]) {
            val = @"DCD";
        }
        else
            val = @"";
        [dataDic setObject:val forKey:@"donor"];
    }
}
/**
 将用户友好表达转换为内部数据格式
 */
-(void)convertDesc2Data:(NSMutableDictionary*)dataDic{
    if ([dataDic objectForKey:@"stage"]) {
        NSString *val = [dataDic objectForKey:@"stage"];
        if ([val isEqualToString:@"手术前"]) {
            val = @"BEFORE";
        }
        else {
            val = @"AFTER";
        }
        [dataDic setObject:val forKey:@"stage"];
    }
    if ([dataDic objectForKey:@"donor"]) {
        NSString *val = [dataDic objectForKey:@"donor"];
        if ([val isEqualToString:@"活体"]) {
            val = @"RELATED";
        }
        else if ([val isEqualToString:@"DCD"]) {
            val = @"UNRELATED";
        }
        [dataDic setObject:val forKey:@"donor"];
    }
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.itemNameArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        cell.textLabel.font=[UIFont systemFontOfSize:15];
        cell.detailTextLabel.font=[UIFont systemFontOfSize:15];
        cell.detailTextLabel.textColor=COLOR(180, 180, 180);
    }
    NSInteger index = ROWINDEX(indexPath);
    if (indexPath.row==7){ //设置手术方式
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = self.itemNameArr[indexPath.row];
    }
    else if (indexPath.row != (self.itemNameArr.count - 1)) {
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = self.itemNameArr[indexPath.row];
        [self.controlArr addObject:cell.detailTextLabel];
        NSString *key = _propertyNameArr[indexPath.row];
        NSString *val = [NSString stringWithFormat:@"%@",[self.opinfo valueForKey:key]];
        cell.detailTextLabel.text = val;
    }
    else if (indexPath.row==self.itemNameArr.count-1) {
        [self layoutDzyView:_otherdiacell rowIndex:index];
        if (![_picCacheDic objectForKey:[NSNumber numberWithInteger:index]]) {
            if (_opinfo.imgUrl.length>0) {
                [self requestPictures:_opinfo.imgUrl?_opinfo.imgUrl:@"" ctrlIndex:index];
            }
        }
        return _otherdiacell;
    }
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    self.tempIndexPath=indexPath;
    if (indexPath.row==3) { //器官来源，选择 活体or器官捐献
        IQActionSheetPickerView *picker = [[IQActionSheetPickerView alloc] initWithTitle:@"" delegate:self];
        picker.titleFont = [UIFont systemFontOfSize:12];
        picker.titleColor = [UIColor redColor];
        [picker setTag:2];
        [picker setTitlesForComponents:@[self.ogonOriginArr]];
        [picker show];
    }
    else if (indexPath.row==4) { //手术日期
        IQActionSheetPickerView *picker = [[IQActionSheetPickerView alloc] initWithTitle:@"" delegate:self];
        [picker setTag:3];
        [picker setActionSheetPickerStyle:IQActionSheetPickerStyleDatePicker];
        [picker show];
    }
    else if (indexPath.row==6){
        [self goSearchHospital];
    }
    else if (indexPath.row==7){
        OperateWayTableViewController *v = [OperateWayTableViewController new];
        v.opway = self.opinfo.operationOperandiDTO;
        v.delegate = self;
        [self.navigationController pushViewController:v animated:YES];
    }
    else if (indexPath.row<self.itemNameArr.count-1) {
        SinglelineTextFormViewController *v = [SinglelineTextFormViewController new];
        v.indexPath = indexPath;
        v.delegate = self;
        [self.navigationController pushViewController:v animated:YES];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==self.itemNameArr.count-1) {
        return 151;
    }
    return 44;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 1;
}

#pragma mark 内部业务逻辑
//创建图片控件
-(void)layoutDzyView:(UITableViewCell*)cell rowIndex:(NSInteger)rowindex{
    if (self.pickerIndexCache[[NSNumber numberWithInteger:rowindex]]) {
        return;
    }
    self.pickerIndexCache[[NSNumber numberWithInteger:rowindex]] = @1;
    DzyImgPicker *picker = [[DzyImgPicker alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 115) andParentV:self andMaxNum:6];
    picker.tag = rowindex;
    picker.dzyImgDelegate = self;
    picker.collectionView.scrollEnabled=NO;
    UIView *backView = [cell viewWithTag:1];
    [backView addSubview:picker];
    [self.imgPickerDic setObject:picker forKey:[NSNumber numberWithInteger:rowindex]];
}
//发起图片请求
- (void)requestPictures:(NSString*)urlArrStr ctrlIndex:(NSInteger)index{
    if (![urlArrStr isNotEmpty]) {
        return;
    }
    NSMutableArray *urlArr = [[urlArrStr componentsSeparatedByString:@","] mutableCopy];
    //逆序遍历清除空元素
    for (int i=(int)urlArr.count-1; i>=0; i--) {
        NSString *element = urlArr[i];
        if (element.length==0) {
            [urlArr removeObjectAtIndex:i];
        }
    }
    if (urlArr.count==0) {
        return;
    }
    NSMutableArray *tempImageArr = [NSMutableArray array];
    for (NSString *url in urlArr) {
        NSURL *ourl = [NSURL URLWithString:url];
        UIImageView *iv = [[UIImageView alloc] init];
        [_picCacheArr addObject:iv];
        [iv sd_setImageWithURL:ourl completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            if (image) {
                [tempImageArr addObject:image];
                if (tempImageArr.count == urlArr.count) {
                    DzyImgPicker *picker = [self.imgPickerDic objectForKey:[NSNumber numberWithInteger:index]];
                    [picker giveImages:tempImageArr];
                }
            }
        }];
    }
    [_picCacheDic setObject:@1 forKey:[NSNumber numberWithInteger:index]];
}

#pragma mark - 图片选择控件代理 DzyImgDelegate
- (void)getBase64Images:(NSArray *)imgData index:(NSInteger)tag{
    NSIndexPath *ip = DEROWINDEX(tag);
    if (ip.row==self.itemNameArr.count-1){
        self.opinfo.images = [imgData mutableCopy];
    }
}

#pragma mark - IQActionSheetPickerViewDelegate
-(void)actionSheetPickerView:(IQActionSheetPickerView *)pickerView didSelectTitles:(NSArray *)titles{
    UILabel *cellLabel=_controlArr[self.tempIndexPath.row];
    NSString *valStr = [titles componentsJoinedByString:@""];
    cellLabel.text = valStr;
    [self.opinfo setValue:valStr forKey:_propertyNameArr[_tempIndexPath.row]];
}

-(void)actionSheetPickerView:(IQActionSheetPickerView *)pickerView didSelectDate:(NSDate *)date{
    UITableViewCell *cell=[self.tableView cellForRowAtIndexPath:self.tempIndexPath];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    if (pickerView.tag==3) {
        [formatter setDateStyle:NSDateFormatterMediumStyle];
        [formatter setTimeStyle:NSDateFormatterNoStyle];
        [formatter setDateFormat:@"yyyy-MM-dd"];
        cell.detailTextLabel.text=[formatter stringFromDate:date];
        [self.opinfo setValue:cell.detailTextLabel.text forKey:@"opTime"];
    }
}

#pragma mark 医院搜索相关
//获取所有医院
- (void)getHostpitalData{
    [[YZENetwork sharedInstace]getRequestWithUrl:[BASE stringByAppendingString:URL_SuggestionHospital] parameters:nil delegate:self requestTag:3 successBlock:^(id responseObject) {
        self.commonHospitalArr = [RPHospitalInfo mj_objectArrayWithKeyValuesArrayAdd:responseObject[@"common"]];
        self.hospitalArr = [RPHospitalInfo mj_objectArrayWithKeyValuesArrayAdd:responseObject[@"all"]];
        NSMutableArray *tempAll = [self.hospitalArr mutableCopy];
        //整理数据
        //1.取 广东 和 广州 开头的
        NSMutableArray *guangArr = [NSMutableArray array];
        NSEnumerator *en = [tempAll reverseObjectEnumerator];
        RPHospitalInfo *h1;
        while (h1 = [en nextObject]) {
            if ([h1.name rangeOfString:@"广东"].location!=NSNotFound
                || [h1.name rangeOfString:@"广州"].location!=NSNotFound) {
                [guangArr addObject:h1.name];
                [tempAll removeObject:h1];//移除广字头医院
            }
        }
        NSMutableDictionary *dic1 = [NSMutableDictionary dictionary];
        dic1[@"firstLetter"] = @"广";
        dic1[@"content"] = guangArr;
        [self.sortedHospitalArr addObject:dic1];
        //常用医院
        NSMutableArray *changArr = [NSMutableArray array];
        for (RPHospitalInfo *h2 in _commonHospitalArr) {
            [changArr addObject:h2.name];
        }
        NSMutableDictionary *dic2 = [NSMutableDictionary dictionary];
        dic2[@"firstLetter"] = @"常";
        dic2[@"content"] = changArr;
        [self.sortedHospitalArr addObject:dic2];
        //其它医院
        NSMutableArray *hospitalNameArr = [NSMutableArray array];
        for (RPHospitalInfo *h3 in tempAll) {
            [hospitalNameArr addObject:h3.name];
        }
        self.sortedHospitalArr  = [[hospitalNameArr arrayWithPinYinFirstLetterFormat] mutableCopy];
        [self.sortedHospitalArr insertObject:dic2 atIndex:0];
        [self.sortedHospitalArr insertObject:dic1 atIndex:0];
        self.isSearched = NO;
    }];
}

-(void)goSearchHospital{
    //创建控制器
    PYSearchViewController *searchViewController = [PYSearchViewController searchViewControllerWithHotSearches:nil searchBarPlaceholder:NSLocalizedString(@"搜索医院",@"搜索类型") didSearchBlock:^(PYSearchViewController *searchViewController, UISearchBar *searchBar, NSString *searchText) {
        for (RPHospitalInfo *hospital in self.hospitalArr) {
            if ([hospital.name isEqualToString:searchText]) {
                self.opinfo.hospital_id = hospital.ID;
                self.opinfo.hospital_name = hospital.name;
                UILabel *l = self.controlArr[6];
                l.text = hospital.name;
            }
        }
        [searchViewController dismissViewControllerAnimated:YES completion:nil];
    }];
    //设置索引UI样式
    searchViewController.searchSuggestionView.sectionIndexColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:1.0];
    searchViewController.searchSuggestionView.sectionIndexBackgroundColor= [UIColor clearColor];
    // 4. 设置代理
    searchViewController.delegate = self;
    searchViewController.dataSource = self;
    searchViewController.showSearchHistory = NO;
    [searchViewController setSearchSuggestionHidden:NO];
    searchViewController.cancelButton.tintColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1];
    searchViewController.cancelButton.title = @"取消";
    searchViewController.suggestionViewCellSeperatorStyle = UITableViewCellSeparatorStyleSingleLine;
    // 5. 跳转到搜索控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:searchViewController];
    
    [self presentViewController:nav animated:YES completion:^{
        [searchViewController showSuggestionWhenLoaded];//加载即显示searchSuggestion
    }];
}

#pragma mark - PYSearchSuggestionViewDataSource
- (UITableViewCell*)searchSuggestionView:(UITableView *)searchSuggestionView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    if (_isSearched) {
        cell.textLabel.text = self.tobeChoosenArr[indexPath.row];
    }
    else {
        NSString *hospital;
        NSDictionary *dic = self.sortedHospitalArr[indexPath.section];
        NSArray *hospitalNameArr = dic[@"content"];
        hospital = hospitalNameArr[indexPath.row];
        cell.textLabel.text = hospital;
    }
    return cell;
}

- (NSInteger)searchSuggestionView:(UITableView *)searchSuggestionView numberOfRowsInSection:(NSInteger)section{
    if (_isSearched) {
        return [self.tobeChoosenArr count];
    }
    else {
        NSDictionary *dic = self.sortedHospitalArr[section];
        NSArray *hospitalNameArr = dic[@"content"];
        return [hospitalNameArr count];
    }
}

- (NSInteger)numberOfSectionsInSearchSuggestionView:(UITableView *)searchSuggestionView{
    if (_isSearched) {
        return 1;
    }
    else
        return [self.sortedHospitalArr count];
}

- (NSArray *)sectionIndexTitlesForSearchSuggestionView:(UITableView *)searchSuggestionView{
    NSMutableArray *titles = [NSMutableArray array];
    NSEnumerator *en = [self.sortedHospitalArr objectEnumerator];
    NSDictionary *dic;
    while (dic = [en nextObject]) {
        [titles addObject:dic[@"firstLetter"]];
    }
    return titles;
}

- (CGFloat)searchSuggestionView:(UITableView *)searchSuggestionView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

- (CGFloat)searchSuggestionView:(UITableView *)searchSuggestionView heightForHeaderInSection:(NSInteger)section{
    return 30;
}

- (CGFloat)searchSuggestionView:(UITableView *)searchSuggestionView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}
/*
- (NSString*)searchSuggestionView:(UITableView *)searchSuggestionView titleForHeaderInSection:(NSInteger)section{
    NSString *title = @" ";
    if (_isSearched) {
        title = @"搜索到如下结果";
    }
    else if([self.sortedHospitalArr count]>0){
        NSDictionary *dic = self.sortedHospitalArr[section];
        title = dic[@"firstLetter"];
    }
    return title;
}
*/
- (UIView *)searchSuggestionView:(UITableView *)searchSuggestionView viewForHeaderInSection:(NSInteger)section{
    UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, searchSuggestionView.frame.size.width, 30)];
    header.backgroundColor = COLOR_BG_GRAY;
    UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, header.width-10, header.height)];
    title.font = [UIFont systemFontOfSize:14];
    title.textAlignment = NSTextAlignmentLeft;
    title.textColor = BLACK_COLOR;
    
    if (_isSearched) {
        title.text = @"搜索到如下结果";
    }
    else if([self.sortedHospitalArr count]>0){
        NSDictionary *dic = self.sortedHospitalArr[section];
        title.text = dic[@"firstLetter"];
        if ([title.text rangeOfString:@"常"].location!=NSNotFound) {
            title.text = @"常用医院";
        }
    }
    [header addSubview:title];
    
    return header;
}

#pragma mark - PYSearchViewControllerDelegate
//在这里进行搜索操作
- (void)searchViewController:(PYSearchViewController *)searchViewController searchTextDidChange:(UISearchBar *)seachBar searchText:(NSString *)searchText
{
    if (searchText.length>0 && ![searchText isEqualToString:@" "]) {
        self.isSearched = YES;
        //后台线程搜索
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.tobeChoosenArr removeAllObjects];
            for (RPHospitalInfo *hospital in self.hospitalArr) {
                if ([hospital.name rangeOfString:searchText].location!=NSNotFound) {
                    [self.tobeChoosenArr addObject:hospital.name];
                }
            }
            [searchViewController.searchSuggestionView reloadData];
        });
    }
    else{
        self.isSearched = NO;
        [searchViewController.searchSuggestionView reloadData];
    }
}

#pragma mark - SinglelineTextFormViewControllerDelegate
- (void)backData:(NSString *)content identifier:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    cell.detailTextLabel.text = content;
    [self.opinfo setValue:content forKey:self.propertyNameArr[indexPath.row]];
}

#pragma mark - OperateWayTableViewControllerDelegate
- (void)backOperationData:(OperationOperandiDTO *)data{
    self.opinfo.operationOperandiDTO = data;
}

#pragma mark - 配置数据
-(NSArray*)statusArr{
    if (!_statusArr) {
        _statusArr = @[@"手术前", @"手术后"];
    }
    return _statusArr;
}

-(NSArray*)ogonOriginArr{
    if (!_ogonOriginArr) {
        _ogonOriginArr = @[@"活体", @"DCD"];
    }
    return _ogonOriginArr;
}

- (NSMutableArray *)tobeChoosenArr{
    if (!_tobeChoosenArr) {
        _tobeChoosenArr = [NSMutableArray array];
    }
    return _tobeChoosenArr;
}

- (NSMutableArray *)sortedHospitalArr{
    if (!_sortedHospitalArr) {
        _sortedHospitalArr = [NSMutableArray array];
    }
    return _sortedHospitalArr;
}

- (NSMutableDictionary *)pickerIndexCache{
    if (!_pickerIndexCache) {
        _pickerIndexCache = [NSMutableDictionary  dictionary];
    }
    return _pickerIndexCache;
}

- (OperationInfoBean *)opinfo{
    if (!_opinfo) {
        _opinfo = [OperationInfoBean new];
        _opinfo.stage = @"AFTER";
    }
    return _opinfo;
}

#pragma mark - 网络代理
- (void)OnStartWithRequestTag:(int)tag{}
- (void)OnFinishWithRequestTag:(int)tag{}
- (void)OnSuccess:(id)responseObject requestTag:(int)tag{}
- (void)OnFail:(NSString *)errorMsg errorCode:(NSInteger)errorCode requestTag:(int)tag{
    if (tag==2) {
        [QMUITips hideAllToastInView:self.view animated:YES];
        [QMUITips showError:@"提交失败！" inView:self.view hideAfterDelay:2];
    }
}

@end
